package main

import (
	"binseek/pkg/finder"
	"binseek/pkg/subjects"
	"binseek/pkg/utils"
	"fmt"
	"os"
	"path/filepath"
	"strings"
)

var (
	findObj finder.Finder
	kindStr = "ip, ip2"
)

func main() {
	if len(os.Args) <= 2 {
		return
	}
	kind, targets := os.Args[1], os.Args[2:]
	if !strings.Contains(kindStr, kind) {
		fmt.Printf("功能 %s 暂时未实现\n", kind)
		return
	}
	var err error
	if kind == "ip2" {
		fileName := filepath.Join(utils.GetCurrDir(), "qqwry.dat")
		findObj, err = subjects.NewIpWry(fileName)
	} else {
		fileName := filepath.Join(utils.GetCurrDir(), "ipaddr.dat")
		findObj, err = subjects.NewIpAddr(fileName)
	}
	if err != nil {
		fmt.Println("数据文件不存在或打不开")
		return
	}
	var info string
	for _, ip := range targets {
		info, err = findObj.Find(ip)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("%s\t%s\n", ip, info)
		}
	}
}
